import React, { useEffect, useState } from 'react'
import Taro from '@tarojs/taro'
import currentEnv from '../../../configure/currentEnv';
import {View,Text, Image} from '@tarojs/components'
import './index.scss'
import { getServerCurrentTime } from '../../services/giftCard';

export default function CouponDetail() {
  const [info,setInfo] = useState({})
  const [id,setId] = useState('')
  const [businessType,setBusinessType] = useState('')
  useEffect(()=>{
    const {router} = Taro.getCurrentInstance()
    setId(router.params?.id)
    setBusinessType(router.params?.businessType)
    Taro.showLoading({title:'加载中...'})
    Taro.$post(`/wallet/app/coupon/couponMessage`,{
      id:router.params?.id,
      businessType:router.params?.businessType
    },'1').then(res=>{
      if(res.code == '1'){
        setInfo(res.content)
        getServerCurrentTime().then(res=>{
          if(res.code == '1'){
            console.log(res.content.currentTime)
          }
        })
      }else{
        Taro.$toast(res.message)
      }
    })
  },[])
  const filterRichTextContent = (content = '') => {
    return content.toString().replace(/\<img\s+/gi, `<img mode="widthFix" `);
  };
  return (
    <View className='coupon-detail'>
      <View className="detail-header">
        <View className="header-info">
          <View className="info-h2 dot2">{info.voucherName}</View>
          <View className="info-p">有效期至 {info.effectEndDate}</View>
        </View>
        <View className="header-price">
          <View className="price-info"><Text style={{fontSize:10,fontWeight:400}}>￥</Text>{info.couponFace}</View>
          {info.threshold == '有门槛'?info.thresholdValue*1>0?`满${info.thresholdValue}减${info.couponFace}`:'':'无门槛'}
        </View>
      </View>
      {/* <View className="detail-box">
        <View className="detail-item">
          <View className="item-label">适用活动</View>
          <Text style={{marginLeft: 'auto',marginRight:4}}>2024英雄联盟季中冠军赛</Text>
          <Text className='at-icon at-icon-chevron-right' style={{fontSize:24}}></Text>
        </View>
        <View className="detail-item" onClick={()=>{
          Taro.setStorageSync('cinemaIds',info.cinemaId)
          Taro.navigateTo({
            url:`/mainPages/apply-cinema/index`
          })
        }}>
          <View className="item-label">适用影院</View>
          <Text style={{marginLeft: 'auto',marginRight:4}}>{info.cinemaCount}家影院</Text>
          <Text className='at-icon at-icon-chevron-right' style={{fontSize:16}}></Text>
        </View>
      </View> */}
      <View className="detail-box">
        <View className="item-label">使用规则</View>
        <View className='box-p' dangerouslySetInnerHTML={{
          __html: filterRichTextContent(info.detailInfo),
        }}>
        </View>
      </View>
      <View className="detail-box">
        <View className="detail-item">
          <View className="item-label">使用须知</View>
          <View className="item-strong">《优惠券使用规则》</View>
        </View>
      </View>
      <View className="add-footer">
        <View className="footer-button" onClick={()=>{
          Taro.reLaunch({
            url:currentEnv.project=='yingjing'?'/pages/index/index':'/pages/movie/index'
          })
        }}>立即使用</View>
      </View>
    </View>
  )
}
